﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class WBBSTController
    {
        [ChildActionOnly]
        public ActionResult PCUTFWB(string returnUrl)
        {
            ModelState.Clear();
            MABF.CWBB.CMTR = MABF.MAM.UIAM.VU0;
            return PartialView(MABF.CWBB);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult PCUTFWB(WBBSTModel model, string returnUrl)
        {
            try
            {
                ModelState.Clear();
                CUTFCommand();
            }
            catch (Exception ex)
            {
                INFO = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP);
        }

        public void CUTFCommand()
        {

            if (MABF.CWBB.QUALITY.Trim().Length == 0)
                MABF.CWBB.QUALITY = "1A";
            if (MABF.CWBB.dwWB["ABFAFOLGE"].ToString().Trim().Length > 0)
            {
                MABF.CWBB.dwWB["WBBAFOLGEVON"] = MABF.CWBB.dwWB["ABFAFOLGE"];
            }
            DataRow dwMaster = MABF.CWBB.dwWB;
            string WFART = MABF.CWBB.ART;
            string MACHINEID = MABF.MAM.MKEY;
            dwMaster["WBBWMNRKRS"] = MACHINEID.Substring(0, 2);
            dwMaster["WBBWMLFDNR"] = MACHINEID.Substring(2, 4);
            dwMaster["WBBWMPOS"] = MACHINEID.Substring(6, 2);
            dwMaster["WBBPACKNR"] = dwMaster["WBBPOS"];
            double CMTR = double.Parse(MABF.CWBB.CMTR) * 1000;
            string NSTKNR = "";
            PM["dwWB"] = dwMaster;
            PM["CMTR"] = CMTR;
            PM["RUNID"] = RUNID;
            PM["WFART"] = WFART;
            PM["QIMACHINE"] = MACHINEID;
            PM["QUALITY"] = MABF.CWBB.QUALITY.ToString();
            PM["WH2"] = MABF.CWBB.WHP;
            PM["FWIDTH"] = dwMaster["WAFBRTU"].ToString();
            PM["IsInsert"] = false;
            PM["PRINTER"] = MABF.MAM.Printer;
            PM["SHIFT"] = MABF.SHIFT;
            PM["LOOMID"] = "";
            NSTKNR = VHP.VWBB.CUTFWB(PM);//首次产生0长度布卷//启动验布界面，此时码表应当度数为0
            VHP.VABP.ABFQTYPROD(dwMaster, "QTYMTR", "QI04".PadRight(8), MACHINEID, MABF.CWBB.dwWB["WBBTP"].ToString(), WFART, CMTR * 0.001);
            MABF.CWBB.WBBINBSTMTR = (double.Parse(MABF.CWBB.WBBINBSTMTR) + CMTR * 0.001).ToString();
            DataSet Set = new DataSet();
            Set.Merge(dwMaster.Table);
            PM["Set"] = Set;
            VHP.VWBB.PrintWB(PM);
        }
    }
}
